import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    OpenTwoRouter,
    UploadOperationBtn,
    OpenExcelButton,
    ExecuteButton,
} from '../Common/options'

export const InfoSmartReports = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { userUuid } = await JSON.parse(window.sessionStorage.getItem('UserInfo'))

    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [<AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />],
        columns: [
            { ...commonTableList.SearchSort, selectType: 'InfoSmartReports' },
            commonTableList.uuid,
            { ...commonTableList.tableName, title: '主题' },
            { ...commonTableList.isEnabled, title: '是否锁定', hideInSearch: true, rules: true },

            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.StartDate,
            commonTableList.EndDate,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 400,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { createUserUuid, uuid } = record
                    return [
                        createUserUuid === userUuid && (
                            <UploadOperationBtn
                                key="A01"
                                title="上传模板"
                                modal="TableList"
                                actionRef={actionRef}
                                OptionsEvent={OptionsEvent}
                                data={{ oneData: record, pos: 'posInfoSmartReportsGenerateData' }}
                            />
                        ),
                        createUserUuid === userUuid && (
                            <OpenTwoRouter
                                key="A02"
                                title="上报人员"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'AnnexPerson',
                                    actionRef,
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ),
                        <OpenExcelButton
                            key="open"
                            title="上报数据"
                            OptionsEvent={OptionsEvent}
                            data={{
                                submit: true,
                                save: true,
                                url: 'getInfoSmartReportsGetSmartReportExcel',
                                pos: 'posInfoSmartReportsUploadExcelDetail',
                                uuid,
                                createUserUuid,

                                // flowUuid,
                            }}
                        />,
                        <ExecuteButton
                            actionRef={actionRef}
                            key="fiv"
                            danger={true}
                            title="清除明细"
                            url="posInfoSmartReportsRemoveInfoSmartReportDetail"
                            data={{ uuid, createUserUuid }}
                            tips="明细数据已清除!"
                            fun="delete"
                        />,
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }

    return data
}
